package io.tim.webserver.simple02.util;

import java.util.*;
import java.io.*;

/**
 * 读取配置文件中的配对信息
 * 
 * @author Zhang Nan
 * @since [28/02/2017]
 *
 */
public class Settings {

	private static String ICONS_PATH;
	private static String SERVER_ROOT;
	private static String WELCOME;
	private static String PORT;
	private static String LOG_PATH;
	private static Map<String, String> confMap = new HashMap<String, String>();

	public void readConfFile(String ConfFileName) throws IOException {

		String str = "";

		File nets = new File(ConfFileName);
		BufferedReader Bw = null;

		if (nets.canRead()) {

			FileReader fw = new FileReader(nets);
			Bw = new BufferedReader(fw);
		}

		while ((str = Bw.readLine()) != null) {
			String[] lineSet = str.split(" ");
			confMap.put(lineSet[0], lineSet[lineSet.length - 1]);
		}

		Bw.close(); // close the Configuration File

	}

	public String getServerRoot() {
		return confMap.get("ServerRoot");
	}

	public int getServerPort() {
		return Integer.parseInt(confMap.get("Port"));
	}

	public String getServerHomePage() {
		return confMap.get("Welcome");
	}

	public String getServerIcons() {
		return confMap.get("Icons");
	}

	public String getServerLog() {
		return confMap.get("LogFile");
	}
}